package tests;


import common.Utils;
import org.openqa.selenium.By;

import java.io.IOException;

public class HomePage extends Utils {
    public static String url ="http://8.137.19.140:9090/blog_list.html";
    public HomePage() {
        super(url);
    }
    //登录状态下正常打开
    public void ByLogin(){
        //先登录
        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#submit")).click();
        //测试是否正常打开
        driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > a"));
        String title = driver.getTitle();
        assert title.equals("博客列表页");
    }

    //未登录状态
    public void ByNoLogin() throws IOException {
        //因为登录成功后已经在列表页,点击注销
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)")).click();
        //跳转到登录页面
        driver.findElement(By.cssSelector("#submit"));
        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#submit")).click();
        //在测试能否正常打开
        driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1) > a"));
    }

}
